package cn.net.zj.scan.adapter;

/**
 * Created by Administrator on 2016/11/25.
 */

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.net.zj.scan.R;
import cn.net.zj.scan.bean.OutHouseBean;

public class OutHomeListAdapter extends
        RecyclerView.Adapter<OutHomeListAdapter.ViewHolder>
{

    private LayoutInflater mInflater;
    private List<OutHouseBean> mDatas;
    Context mContext;

    public OutHomeListAdapter(Context context, List<OutHouseBean> orderList) {
        mInflater = LayoutInflater.from(context);
        mDatas = orderList;
        mContext =context;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder
    {
        public ViewHolder(View arg0)
        {
            super(arg0);
        }

        TextView tv_cus_code,tv_c_name,tv_number,tv_specType,tv_batchno,tv_stock_no,tv_position;
    }

    @Override
    public int getItemCount()
    {
        return mDatas.size();
    }

    /**
     * 创建ViewHolder
     */
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i)
    {
        View view = mInflater.inflate(R.layout.item_order,
                viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(view);

        viewHolder.tv_cus_code = (TextView) view.findViewById(R.id.tv_cus_code);
        viewHolder.tv_c_name = (TextView) view.findViewById(R.id.tv_c_name);

        viewHolder.tv_number = (TextView) view.findViewById(R.id.tv_number);
        viewHolder.tv_specType = (TextView) view.findViewById(R.id.tv_specType);
        viewHolder.tv_batchno = (TextView) view.findViewById(R.id.tv_batchno);
        viewHolder.tv_stock_no = (TextView) view.findViewById(R.id.tv_stock_no);
        viewHolder.tv_position = (TextView) view.findViewById(R.id.tv_position);

        return viewHolder;
    }

    /**
     * 设置值
     */
    @Override
    public void onBindViewHolder(final ViewHolder viewHolder, final int i)
    {
        viewHolder.tv_cus_code.setText("客户编码:"+mDatas.get(i).getC_cuscode()+"");
        viewHolder.tv_c_name.setText("产品名称:"+mDatas.get(i).getC_name()+"");
        viewHolder.tv_number.setText("产品序号:"+mDatas.get(i).getC_number()+"");
        viewHolder.tv_specType.setText("规格:"+mDatas.get(i).getC_spectype()+"");
        viewHolder.tv_batchno.setText("批号:"+mDatas.get(i).getC_batchno()+"");
        viewHolder.tv_stock_no.setText("仓位:"+mDatas.get(i).getC_stockno()+"");

        viewHolder.tv_position.setText(""+i+"");

        if( mOnItemClickListener!= null) {
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.onClick(i);
                }
            });
            viewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    mOnItemClickListener.onLongClick(i);
                    return false;
                }
            });
        }
    }



    private OnItemClickListener mOnItemClickListener;
    public void setOnItemClickListener(OnItemClickListener onItemClickListener ){
        this. mOnItemClickListener=onItemClickListener;
    }
    public interface OnItemClickListener{
        void onClick( int position);
        void onLongClick( int position);
    }

}